package durst.data;

import java.util.Date;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.sdicons.json.mapper.JSONMapper;

import durst.data.dao.impl.MessageDao;
import durst.data.json.MessageJSONHelper;

@DatabaseTable(tableName = "Message", daoClass = MessageDao.class)
public class CSDMessage extends CSDEntity {
	public static final String TARGET_ID = "target_id";
	public static final String SENDER_ID = "sender_id";
	static {
		JSONMapper.addHelper(new MessageJSONHelper());
	}
	
	@DatabaseField(generatedId = true)
	private int id;
	
	@DatabaseField(canBeNull = false, foreign = true, columnName = TARGET_ID)
	private Account target;
	
	@DatabaseField(canBeNull = false, foreign = true, columnName = SENDER_ID)
	private Account sender;
	
	@DatabaseField(canBeNull = false)
	private String title;
	
	@DatabaseField(canBeNull = false) 
	private String contents;
	
	@DatabaseField(canBeNull = false)
	private Date sent;

	@DatabaseField(canBeNull = false) 
	private boolean read;
	
	public CSDMessage() {}
	
	public CSDMessage(Account target, Account sender, String title, String contents, Date sent) {
		this.target = target;
		this.sender = sender;
		this.title = title;
		this.contents = contents;
		this.sent = sent;
		this.read = false;
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Account getTarget() {
		return target;
	}

	public void setTarget(Account target) {
		this.target = target;
	}

	public Account getSender() {
		return sender;
	}

	public void setSender(Account sender) {
		this.sender = sender;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContents() {
		return contents;
	}

	public void setContents(String contents) {
		this.contents = contents;
	}

	public Date getSent() {
		return sent;
	}

	public void setSent(Date sent) {
		this.sent = sent;
	}

	public void setRead(boolean read) {
		this.read = read;
	}

	public boolean isRead() {
		return read;
	} 
}
